package org.deadline.model.baseapp;

import flexjson.JSONDeserializer;
import flexjson.JSONSerializer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deadline.model.config.Enumeration;
import org.deadline.model.user.Person;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
public class NotificationShedule extends BaseEntity  implements Serializable {

    @ManyToOne
    private Person person;

    @NotNull
    @Size(min = 2, max = 500)
    private String notifyTo;

    @NotNull
    @Size(min = 2, max = 500)
    private String notifyType;

    @NotNull
    @Temporal(TemporalType.TIMESTAMP)
    @DateTimeFormat(style = "M-")
    private Date notifyDate;

    @NotNull
    @Size(min = 100, max = 2000)
    private String comment;

    @ManyToOne
    private Enumeration notifyStatus;

    @ManyToOne
    private NotificationResource notificationResource;

	@Id
	@Column(name="id",unique=true,nullable=false)
	@SequenceGenerator(name="notification_shedule_seq_gen",sequenceName="notification_shedule_seq")
	@GeneratedValue(generator="notification_shedule_seq_gen",strategy=GenerationType.TABLE)
	@Generated(GenerationTime.INSERT)
	private Long id;

	
	public Person getPerson() {
        return this.person;
    }

	public void setPerson(Person person) {
        this.person = person;
    }

	public String getNotifyTo() {
        return this.notifyTo;
    }

	public void setNotifyTo(String notifyTo) {
        this.notifyTo = notifyTo;
    }

	public String getNotifyType() {
        return this.notifyType;
    }

	public void setNotifyType(String notifyType) {
        this.notifyType = notifyType;
    }

	public Date getNotifyDate() {
        return this.notifyDate;
    }

	public void setNotifyDate(Date notifyDate) {
        this.notifyDate = notifyDate;
    }

	public String getComment() {
        return this.comment;
    }

	public void setComment(String comment) {
        this.comment = comment;
    }

	public Enumeration getNotifyStatus() {
        return this.notifyStatus;
    }

	public void setNotifyStatus(Enumeration notifyStatus) {
        this.notifyStatus = notifyStatus;
    }

	public NotificationResource getNotificationResource() {
        return this.notificationResource;
    }

	public void setNotificationResource(NotificationResource notificationResource) {
        this.notificationResource = notificationResource;
    }

	public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

	private static final long serialVersionUID = 1L;

	public String toJson() {
        return new JSONSerializer().exclude("*.class").deepSerialize(this);
    }

	
	public Long getId() {
	    return this.id;
	}

	public void setId(Long id) {
	    this.id = id;
	}

	public static NotificationShedule fromJsonToNotificationShedule(String json) {
        return new JSONDeserializer<NotificationShedule>().use(null, NotificationShedule.class).deserialize(json);
    }

	public static String toJsonArray(Collection<NotificationShedule> collection) {
        return new JSONSerializer().exclude("*.class").deepSerialize(collection);
    }

	public static Collection<NotificationShedule> fromJsonArrayToNotificationShedules(String json) {
        return new JSONDeserializer<List<NotificationShedule>>().use(null, ArrayList.class).use("values", NotificationShedule.class).deserialize(json);
    }
}
